package cn.xiuxius.embedded.command.converter;

import picocli.CommandLine.ITypeConverter;
import picocli.CommandLine.TypeConversionException;

import java.io.File;
import java.nio.file.Path;

public class ExistingDirectoryConverter implements ITypeConverter<Path> {
    @Override
    public Path convert(String value) {
        File dir = new File(value);
        if (!dir.exists() || !dir.isDirectory()) {
            throw new TypeConversionException("Directory does not exist: " + value);
        }
        return dir.toPath();
    }
}
